package com.situ.controller;

import com.situ.util.LayData;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/api")
public class LogoutController {

    @PostMapping("/logout")
    public LayData logout(HttpServletRequest request, HttpServletResponse response) {
        // 获取当前 session
        HttpSession session = request.getSession(false);

        if (session != null) {
            // 使 session 失效
            session.invalidate();
        }

        // 清除客户端 cookie（如果有）
        // 例如：response.setHeader("Set-Cookie", "token=; Path=/; Max-Age=0; HttpOnly");

        // 返回成功响应
        LayData data = new LayData();
        data.setCode(0);
        data.setMsg("退出登录成功");
        return data;
    }
}